<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */

namespace App\Support;

class Message
{
    public static function create(string $event, array $data, array $options = []): array
    {
        return [
            'uuid' => uniqid(strval(mt_rand(0, 1000))),
            'event' => $event,
            'data' => $data,
            'options' => $options,
        ];
    }

    /**
     * 推送消息至 Redis 订阅通道中.
     */
    public static function publish(array $message)
    {
        // 推送消息到 Redis 订阅中
        redis()->publish('websocket', is_string($message) ? $message : json_encode($message));
    }
}
